/**
 * Created by Administrator on 2017/3/25.
 */
var app = angular.module('app',['ng','ngRoute','ui.bootstrap']);
// 路由
app.config(function ($routeProvider) {
    $routeProvider
        .when('/home',{
            templateUrl:'tpl/home.html',
            controller:'homeCtrl'
        })
        .when('/home/:coluId',{
            templateUrl:'tpl/home.html',
            controller:'homeCtrl'
        })
        .when('/login',{
            templateUrl:'tpl/login.html',
           /* controller:'homeCtrl'*/
        })
        .when('/special',{
            templateUrl:'tpl/speci.html',
            controller:'specCtrl'
        })
        .when('/special/:fileId/:linkID',{
            templateUrl:'tpl/speci.html',
            controller:'specCtrl'
        })
        .when('/special/:fileId/:linkID/:colID',{
            templateUrl:'tpl/speci.html',
            controller:'specCtrl'
        })
        .when('/author',{
            templateUrl:'tpl/author.html',
            controller:'authorCtr'
        })
        .when('/register',{
            templateUrl:'tpl/register.html',
            controller:'regitCtr'
        })
        .when('/channel',{
            templateUrl:'tpl/channel.html',
            controller:'chanCtr'
        })
        //直播
        .when('/live',{
            templateUrl:'tpl/live.html',
            controller:'liveCtr'
        })
        .when('/detailLive',{
            templateUrl:'tpl/liveDetail.html',
            controller:'liveDetCtr'
        })
        .when('/detailLive/:linkID',{
            templateUrl:'tpl/liveDetail.html',
            controller:'liveDetCtr'
        })
        .when('/detailLive/:fileId/:linkID',{
            templateUrl:'tpl/liveDetail.html',
            controller:'liveDetCtr'
        })
        .when('/detailVedio',{
            templateUrl:'tpl/detailVedio.html',
            controller:'detailVedioCtr'
        })
        .when('/detailVedio/:fileId',{
            templateUrl:'tpl/detailVedio.html',
            controller:'detailVedioCtr'
        })
        .when('/detailActivity',{
            templateUrl:'tpl/detailAct.html',
            controller:'detailActCtr'
        })
        .when('/detailActivity/:fileId',{
            templateUrl:'tpl/detailAct.html',
            controller:'detailActCtr'
        })
        .when('/detailSpec',{
            templateUrl:'tpl/detailSpec.html',
            controller:'detailSpecCtr'
        })
        .when('/detailSpec/:columnId',{
            templateUrl:'tpl/detailSpec.html',
            controller:'detailSpecCtr'
        })
        .when('/detail',{
            templateUrl:'tpl/detail.html',
            controller:'detailCtrl'
        })
        .when('/detail/:fileId',{
            templateUrl:'tpl/detail.html',
            controller:'detailCtrl'
        })
        //组图详情
        .when('/detailPicture',{
            templateUrl:'tpl/detail.html',
            controller:'detailCtrl'
        })
        .when('/detailPicture/:fileId',{
            templateUrl:'tpl/detailPicture.html',
            controller:'detailCtrl'
        })
        //问政详情
        .when('/detailQa',{
            templateUrl:'tpl/qaPage.html',
            controller:'qaCtrl'
        })
        .when('/detailQa/:fileId',{
            templateUrl:'tpl/qaPage.html',
            controller:'qaCtrl'
        })
        //问吧详情
        .when('/detailSubject',{
            templateUrl:'tpl/askPage.html',
            controller:'askPageCtrl'
        })
        .when('/detailSubject/:fileId',{
            templateUrl:'tpl/askPage.html',
            controller:'askPageCtrl'
        })
        .when('/commTpl',{
            templateUrl:'tpl/commentTpl.html',
            controller:'commenCtr'
        })
        .when('/commTpl/:fileId',{
            templateUrl:'tpl/commentTpl.html',
            controller:'commenCtr'
        })
        .when('/moreModule',{
            templateUrl:'tpl/moreModule.html',
            controller:'moreModuleCtr'
        })
        .when('/moreModule/:moduleId',{
            templateUrl:'tpl/moreModule.html',
            controller:'moreModuleCtr'
        })
        .otherwise({redirectTo:'/home'});
});
//main controller
app.controller('parentCtrl',
['$scope','$location','$http','$rootScope','$routeParams','$sce','$window','$interval', function ($scope,$location,$http,$rootScope,$routeParams,$sce,$window,$interval) {
    //loading提示
    $("#globalLoading").css({
        top:'10rem',
        opacity:'1'
    });

    $scope.sceControl = $sce.trustAsResourceUrl;
    //加载更多按钮隐藏
    $scope.loadMoreButtonOne = false;
    $scope.jump = function (arg) {
        $("body").animate({scrollTop: 0}, 300);
        $location.path(arg, {cache:true}, { reload: true });
    };

    //h5稿件跳转
    $scope.h5Jump= function (argUrl) {
        window.open(argUrl,'_self')
    };

    //用户是否已登录
    $interval(function () {
        $scope.uid_fouNder= doGetCookie('uid_fouNder');
        uid_fouNder=doGetCookie('uid_fouNder');
        $scope.username_fouNder= doGetCookie('username_fouNder');
        username_fouNder=doGetCookie('username_fouNder');
        if(!$scope.uid_fouNder){
            console.log("未登录");
        }else{
            console.log("用户已经登录"+$scope.uid_fouNder);

        }
    },3000);


    //获取全局配置信息
    $scope.getCommentInfo=function(){

        $http.jsonp(commInfo+'&jsoncallback=JSON_CALLBACK'
        ).success(function(data,header,config,status){
            console.log("全局评论信息");
            console.log(data);
            $scope.siteConfig=data.siteConfig.discuss;
            //评论框提示语
            //defaultHint=$scope.siteConfig.defaultHint;
            //siteConfig.defaultHint=$scope.siteConfig.defaultHint;
            ////评论框标题提示语
            //siteConfig.defaultTitle=$scope.siteConfig.defaultTitle;
            ////官方评论用户名
            //siteConfig.defaultName=$scope.siteConfig.defaultName;
            //$rootScope.siteConfigDefaultName=$scope.siteConfig.defaultName;
            ////官方评论头像
            //siteConfig.defaultIcon=$scope.siteConfig.defaultIcon;
            //$rootScope.siteConfigDefaultIcon=$scope.siteConfig.defaultIcon;
            //全局评论是否关闭=2关闭
            siteConfig.auditType=$scope.siteConfig.auditType;
            //全局评论颜色
            siteConfig.styleColor=$scope.siteConfig.styleColor;
            //全局是否允许上传评论图片
            siteConfig.showPic=$scope.siteConfig.showPic;
            //是否允许评论时上传图片false和true
            siteConfig.showPic=$scope.siteConfig.showPic;

        }).error(function(data,header,config,status){

        });

    };
    $scope.getCommentInfo();




    // 获取导航
    $scope.getNavCou=function(){
        $http.jsonp(navUrl+'&jsoncallback=JSON_CALLBACK'
        ).success(function(data,header,config,status){
            $scope.navData=data;
             navArr=$scope.navData.columns;
            $scope.chanNav(firstPageColumns);
        }).error(function(data,header,config,status){
        });
    };
    $scope.getNavCou();


    // 点击导航更新视图根据点击传入columId号
    bannerCount=0;
    // 轮播图个数
    $scope.chanNav=function (coluId) {
        //记录id方便加载更多使用
        $scope.currentPageId=coluId;
        // var navArr=navDataObj.columns;
        console.log("nav columns");
        console.log(navArr);
        var navIndex=0;
        for(var i=0;i<navArr.length;i++){
            if(coluId==navArr[i].columnId){
                navIndex=i;
                lightIndex=navIndex;
               break;
            }

        }
       // if(navIndex&&navIndex!=0){
          // var transLf=$(".gation .nav ul li").eq(navIndex).offset().left;
        //    var transLf=navIndex*60;
        // if(transLf){
        //     var transLf=$(".gation .nav ul li").eq(navIndex).offset().left;
        // }

           //movNum=-transLf;

           $(".gation .nav ul li").eq(navIndex).siblings().find("a").css("color","#333333");
           $(".gation .nav ul li").eq(navIndex).find("a").css("color","#fc9105");
           $(".gation li .navBotLine").each(function (index,element) {
               $(element).css("display","none");
           })
           $(".gation li .navBotLine").eq(navIndex).css("display","block");
           if(coluId==firstPageColumns){
               $(".gation .nav ul li").eq(navIndex).find("a").css("color","#fc9105");
           }
       // }
       // else if(navIndex==0){
       //     $(".gation .nav ul li").eq(0).find("a").css("color","#fc9105");
       //     $(".gation li .navBotLine").eq(0).css("display","block");
       // }

        //轮播js
        $scope.myInterval = 2000;
        $scope.noWrapSlides = false;
        $scope.active = 0;


        //判断是否有轮播图看topCount,决定是否隐藏banner
        $http.jsonp(navUrl+'&jsoncallback=JSON_CALLBACK'
        ).success(function(data,header,config,status){
            $scope.columDataAll=data;
            var datlist=$scope.columDataAll.columns;
            for(var i=0;i<datlist.length;i++){
                if(datlist[i].columnId==coluId){
                    //根据columnStyle判断加载哪种模板
                    $scope.columnStyle=datlist[i].columnStyle
                    console.log("当前对象")
                    console.log(datlist[i])
                    if(!datlist[i].topCount){
                        $scope.topCountShow=false;
                    }else if(datlist[i].topCount){
                        // 轮播图个数
                        // $scope.bannerCount=datlist[i].topCount;
                         bannerCount=datlist[i].topCount;
                        console.log("轮播个数")
                        console.log(bannerCount)
                        // 含有轮播图处理,只从前20条拿取还是所有数据中判断？？目前是前20条，如果是所有，下面链接换成所有数据请求链接
                        $http.jsonp(articalDataUrl+'columnId='+coluId+'&lastFileId=0&page=0&version=0&jsoncallback=JSON_CALLBACK'
                            ).success(function(datas,header,config,status) {
                            // 存储banner的相关信息
                            $scope.bannerObj = [];
                            $scope.bannerImg = [];
                            var data1=datas.list;

                            var counNum = 0;
                            for (var j = 0; j < data1.length; j++) {
                                if (counNum<bannerCount) { //轮播个数

                                    if (data1[j].isBigPic == 0) { //先取小图
                                        if (data1[j].picSmall) {
                                            $scope.bannerObj.push(data1[j]);
                                            $scope.bannerImg.push({img:data1[j].picSmall,title:data1[j].title,fileId:data1[j].fileId,articleType:data1[j].articleType,linkID:data1[j].linkID,url:data1[j].url});
                                            counNum++;
                                        } else if (data1[j].picMiddle) {
                                            $scope.bannerObj.push(data1[j]);
                                            $scope.bannerImg.push({img:data1[j].picMiddle,title:data1[j].title,fileId:data1[j].fileId,articleType:data1[j].articleType,linkID:data1[j].linkID,url:data1[j].url});
                                            counNum++;
                                        } else if (data1[j].picBig) {
                                            $scope.bannerObj.push(data1[j]);
                                            $scope.bannerImg.push({img:data1[j].picBig,title:data1[j].title,fileId:data1[j].fileId,articleType:data1[j].articleType,linkID:data1[j].linkID,url:data1[j].url});
                                            counNum++;
                                        }
                                    } else if (data1[j].isBigPic == 1) {//先中图
                                        if (data1[j].picMiddle) {
                                            $scope.bannerObj.push(data1[j]);
                                            $scope.bannerImg.push({img:data1[j].picMiddle,title:data1[j].title,fileId:data1[j].fileId,articleType:data1[j].articleType,linkID:data1[j].linkID,url:data1[j].url});
                                            counNum++;
                                        } else if (data1[j].picBig) {
                                            $scope.bannerObj.push(data1[j]);
                                            $scope.bannerImg.push({img:data1[j].picBig,title:data1[j].title,fileId:data1[j].fileId,articleType:data1[j].articleType,linkID:data1[j].linkID,url:data1[j].url});
                                            counNum++;
                                        } else if (data1[j].picSmall) {
                                            $scope.bannerObj.push(data1[j]);
                                            $scope.bannerImg.push({img:data1[j].picSmall,title:data1[j].title,fileId:data1[j].fileId,articleType:data1[j].articleType,linkID:data1[j].linkID,url:data1[j].url});
                                            counNum++;
                                        }
                                    }
                            }
                        }
                                    $scope.topCountShow = true;
                                    if (!$scope.bannerImg[0]) {
                                        $scope.topCountShow = false;
                                    }

                            console.log("图片个数")
                            console.log($scope.bannerImg)
                            }).error(function(data1,header,config,status){
                         });
                    }
                }
            }

            //实现跳转，获取稿件数据,需要先去除轮播图含有的对象，如果直播活动也放在里面？也要切除轮播图中的数据columnId='+coluId +'&lastFileId=0&count=20&rowNumber=0&version=0&jsoncallback=JSON_CALLBACK
            $http.jsonp(articalDataUrl+'columnId='+coluId +'&page=0&lastFileId=0&jsoncallback=JSON_CALLBACK'
            ).success(function (data, header, config, status) {
                // 插入模块
                $scope.modules=data.modules;
                console.log("modeu");
                console.log($scope.modules);
                    var parentMudulesObj=$scope.modules;
                    // 实际模块个数，决定滑块个数,决定是否显示
                    $scope.infaceModules=[];
                    //判断实际个数，只要type=0的普通类型稿件
                    for(var n=0;n<parentMudulesObj.length;n++){
                        if(parentMudulesObj[n].type==0){
                            $scope.infaceModules.push(parentMudulesObj[n]);
                            console.log("目前模块");
                            console.log($scope.infaceModules)
                        }
                    }

                    //根据moduleID关联拿取数据
                    //创建最终返回数据对象数据
                    $scope.childGetMouds=[];
                        for(var p=0;p<$scope.infaceModules.length;p++){
                            (function(p){
                                $http.jsonp(moduleView+'id='+$scope.infaceModules[p].moduleID+'&userID=3&jsoncallback=JSON_CALLBACK'
                                ).success(function (modulData, header, config, status) {
                                    $scope.childGetMouds.push(modulData);
                                    //模块插入位置
                                    modulData.position=$scope.infaceModules[p].position;
                                    modulData.targetColumnId=$scope.infaceModules[p].targetColumn.id;
                                });
                            })(p);
                        }
                        if(p==$scope.infaceModules.length){
                            console.log("实际模块对象最终")
                            console.log($scope.childGetMouds)
                        }


                //切除banner对象，普通稿件数据
                console.log("完整")
                console.log(data)
                var datas=data.list;
                if(bannerCount){
                    // 新增 if($scope.bannerObj)
                    if($scope.bannerObj){
                        for(var i=0;i<$scope.bannerObj.length;i++){
                            for(var j=0;j<datas.length;j++){
                                if(datas[j].fileId==$scope.bannerObj[i].fileId){
                                    datas.splice(j,1);

                                }
                            }
                        }
                    }

                }
                //普通稿件切换banner对象后数据
                if($scope.columnStyle!=221&&$scope.columnStyle!=225&&$scope.columnStyle!=203){
                $scope.Hdata=datas; //所有数据中去除banner中对象
                console.log("Hdata");
                console.log($scope.Hdata);
                //大于20条有加载更多功能
                 if($scope.Hdata.length+bannerCount>=20) {
                     //加载更多页数设置为0
                     artiPageNum = 0;
                     //显示加载更多按钮
                     $scope.loadMoreButtonOne = true;
                     $scope.noLoadMoreButton = false;
                     //最后一篇文章id号
                     $scope.lastArticlFileId = $scope.Hdata[$scope.Hdata.length - 1].fileId;
                     // // 文章页数
                 }else{
                     $scope.noLoadMoreButton=true;
                     $scope.loadMoreButtonOne = false;
                 }

                }
                // }

                //视频切换banner对象后数据
                if($scope.columnStyle==203){
                    vedioPageNum=0;
                    $scope.vedioData=datas;
                    console.log("视频id");
                    console.log($scope.vedioData);
                    console.log($scope.vedioData.duration);
                    //最后视频id
                     if($scope.vedioData.length+bannerCount>=20){
                        $scope.lastVedioFileId=$scope.vedioData[$scope.vedioData.length-1].fileId;
                        //显示直播加载更多按钮
                        $scope.loadMoreButtonOne = true;
                         $scope.noLoadMoreButton=false;
                     }else{
                         $scope.noLoadMoreButton=true;
                         $scope.loadMoreButtonOne = false;
                     }
                }

                //直播切换banner对象后数据
                if($scope.columnStyle==225){
                    $scope.Livedata=datas;
                    console.log("")
                    console.log($scope.Livedata);
                    //加载更多页数设置为0
                    livePageNum=0;
                     if($scope.Livedata.length+bannerCount>=20){
                    $scope.lastLiveFileId=$scope.Livedata[$scope.Livedata.length-1].fileId;
                    //显示直播加载更多按钮
                        $scope.loadMoreButtonOne = true;
                         $scope.noLoadMoreButton=false;
                     }else{
                         $scope.noLoadMoreButton=true;
                         $scope.loadMoreButtonOne = false;
                     }
                }

            }).error(function (data, header, config, status) {
            });
            /*if($scope.currentPageId==304){
            //直播列表数据
            // $scope.sceControl = $sce.trustAsResourceUrl;
            $http.jsonp(liveDataUrl+'columnId=304&lastFileId=0&count=20&rowNumber=0&version=0&jsoncallback=JSON_CALLBACK'
            ).success(function(data,header,config,status){
                $scope.Livedata=data.list;
                console.log("直播")
                console.log($scope.Livedata)
                //最后视频id
                if($scope.Livedata.length>=20){
                    $scope.lastLiveFileId=$scope.Livedata[$scope.Livedata.length-1].fileId;
                    //显示直播加载更多按钮
                    $scope.loadMoreButtonOne = true;
                }

            }).error(function(data,header,config,status){
            });
            }*/
        /*    if($scope.currentPageId==303){
            //视频列表数据
            $http.jsonp(vedioDataUrl+'columnId=303&lastFileId=0&count=20&rowNumber=0&version=0&jsoncallback=JSON_CALLBACK'
            ).success(function(data,header,config,status){
                $scope.vedioData=data.list;
                console.log("视频id");
                console.log($scope.vedioData);
                //最后视频id
                if($scope.vedioData.length>=20){
                    $scope.lastVedioFileId=$scope.vedioData[$scope.vedioData.length-1].fileId;
                    //显示直播加载更多按钮
                    $scope.loadMoreButtonOne = true;
                }
            }).error(function(data,header,config,status){
            });
            }*/
            if($scope.columnStyle==221){
            //活动列表数据
            $http.jsonp(actDataUrl+'page=0&jsoncallback=JSON_CALLBACK'
            ).success(function(data,header,config,status){
                $scope.ActHdata=data.list;
                console.log("活动data");
                console.log($scope.ActHdata);
                // //最后活动id
                // $scope.lastActFileId=$scope.ActHdata[$scope.ActHdata.length-1].fileId;
                // 活动根据page而不是id
                 if($scope.ActHdata.length+bannerCount>=20){
                    //显示直播加载更多按钮
                    $scope.actPageNumb=1;
                    $scope.loadMoreButtonOne = true;
                     $scope.noLoadMoreButton=false;
                 }else{
                     $scope.noLoadMoreButton=true;
                     $scope.loadMoreButtonOne = false;
                 }
            }).error(function(data,header,config,status){
            });
            }


            //loading提示
            $("#globalLoading").animate({
                top:'20px',
                opacity:'0'
            },500);

        }).error(function(data,header,config,status){
        });


        console.log('newSwipers');
        console.log(newSwipers);

    };

    /* //直播列表数据
    // $scope.sceControl = $sce.trustAsResourceUrl;
    $http.jsonp(liveDataUrl+'columnId=9&lastFileId=0&count=20&rowNumber=0&version=0&jsoncallback=JSON_CALLBACK'
    ).success(function(data,header,config,status){
        $scope.Livedata=data;
        //最后视频id
        $scope.lastLiveFileId=$scope.Livedata[$scope.Livedata.length-1].fileId;
        if($scope.Livedata.length>=20){
            //显示直播加载更多按钮
            $scope.loadMoreButtonOne = true;
        }

    }).error(function(data,header,config,status){
    });

    //视频列表数据
    $http.jsonp(vedioDataUrl+'columnId=8&lastFileId=0&count=20&rowNumber=0&version=0&jsoncallback=JSON_CALLBACK'
    ).success(function(data,header,config,status){
        $scope.vedioData=data;
        console.log("视频id");
        console.log($scope.vedioData);
        //最后视频id
        $scope.lastVedioFileId=$scope.vedioData[$scope.vedioData.length-1].fileId;
        if($scope.vedioData.length>=20){
            //显示直播加载更多按钮
            $scope.loadMoreButtonOne = true;
        }
    }).error(function(data,header,config,status){
    });

    //活动列表数据
    $http.jsonp(actDataUrl+'page=0&jsoncallback=JSON_CALLBACK'
    ).success(function(data,header,config,status){
        $scope.ActHdata=data;
        // //最后活动id
        // $scope.lastActFileId=$scope.ActHdata[$scope.ActHdata.length-1].fileId;
        // 活动根据page而不是id
        if($scope.ActHdata.length>=20){
            //显示直播加载更多按钮
            $scope.actPageNumb=1;
            $scope.loadMoreButtonOne = true;
        }
    }).error(function(data,header,config,status){
    });*/
    artiPageNum=0;
    //加载更多按钮
    $scope.loadMore = function (coluId,columnStyle) {
        artiPageNum++;
        console.log(artiPageNum);
        // chanNav中已存 $scope.currentPageId 当前页中的id号
        //chanNav中已存 $scope.lastArticlFileId 最后一篇文章id号
        // 活动视频直播调用接口不同，要做判断
        if(columnStyle!=221&&columnStyle!=225&&columnStyle!=203){
            $http.jsonp(articalDataUrl+'columnId=' + coluId + '&page='+artiPageNum+'&lastFileId='+$scope.lastArticlFileId+'&jsoncallback=JSON_CALLBACK'
                    ).success(function (data, header, config, status) {

                        $scope.lastArticlFileId = data.list[data.list.length-1].fileId;
                        console.log("普通稿件加载更多数据")
                        console.log(data)
                        $scope.Hdata=$scope.Hdata.concat(data.list);
                     if (data.list.length < 20) {
                       //     //没有更多，隐藏按钮
                            $scope.loadMoreButtonOne = false;
                            $scope.noLoadMoreButton=true;
                      }

                    }).error(function (data, header, config, status) {
                    });
        }
        if (columnStyle==225){
                //直播列表
                livePageNum++;
                $http.jsonp(liveDataUrl+'columnId='+coluId+'&page='+livePageNum+'&lastFileId='+$scope.lastLiveFileId+'&jsoncallback=JSON_CALLBACK'
                ).success(function (data, header, config, status) {
                    $scope.Livedata = $scope.Livedata.concat(data.list);
                    console.log('直播加载更多数据dd');
                    console.log(data);
                    $scope.lastLiveFileId = data.list[data.list.length - 1].fileId;
                     if (data.list.length < 20) {
                    //     //没有更多，隐藏按钮
                        $scope.loadMoreButtonOne = false;
                        $scope.noLoadMoreButton=true;
                     }
                }).error(function (data, header, config, status) {
                });
            }
        else if(columnStyle==203){
                //视频列表数据
               vedioPageNum++;
                $http.jsonp(vedioDataUrl+'columnId='+coluId+'&page='+vedioPageNum+'&lastFileId='+$scope.lastVedioFileId+'&jsoncallback=JSON_CALLBACK'
                ).success(function(data,header,config,status){
                    console.log("视频加载更多数据")
                    console.log(data)
                    $scope.vedioData = $scope.vedioData.concat(data.list);
                    $scope.lastVedioFileId = data.list[data.list.length - 1].fileId;
                     if (data.list.length < 20) {
                    //     //没有更多，隐藏按钮
                        $scope.loadMoreButtonOne = false;
                        $scope.noLoadMoreButton=true;
                     }
                }).error(function(data,header,config,status){
                });
            }
        else if(columnStyle==221){
            //活动列表数据
                $http.jsonp(actDataUrl+'page='+$scope.actPageNumb+'&jsoncallback=JSON_CALLBACK'
                ).success(function(data,header,config,status){
                    console.log("活动加载更多数据")
                    console.log(data)
                    $scope.ActHdata = $scope.ActHdata.concat(data.list);
                     if (data.list.length<20) {
                    //     //没有更多，隐藏按钮
                       $scope.loadMoreButtonOne = false;
                       $scope.noLoadMoreButton=true;
                     }
                    // 页数自增
                    $scope.actPageNumb++;
                }).error(function(data,header,config,status){
                });
            }
        // else {
        //         //普通稿件请求地址
        //         $http.jsonp('http://172.19.32.122:81/app_if/getArticles?columnId=' + $scope.currentPageId + '&lastFileId=' + $scope.lastArticlFileId + '&count=20&rowNumber=20&version=0&adv=1&jsoncallback=JSON_CALLBACK'
        //         ).success(function (data, header, config, status) {
        //             $scope.Hdata=$scope.Hdata.concat(data);
        //             $scope.lastArticlFileId=data[data.length-1].fileId;
        //             if (data.length < 20) {
        //                 //没有更多，隐藏按钮
        //                 $scope.loadMoreButtonOne = false;
        //             }
        //         }).error(function (data, header, config, status) {
        //         });
        //     }
    };

        //模态框body点击隐藏
        $scope.hideMode = function () {
            $('#myModal').modal('hide');
        }
        //模态框js-内容图片预览
        $scope.showMoCrenImges = '';
        $scope.showModelImg = function (curIndex, $event) {
            $scope.imgScalImg = [];
            $('#myModal').modal('show');
            $scope.showCurImg = angular.element($event.target);
            $scope.showCurImgUrl = $scope.showCurImg.context.currentSrc;
            var phtos = $scope.showCurImg.parent().parent().parent().find("img");
            for (var i = 0; i < phtos.length; i++) {
                $scope.imgScalImg.push(phtos[i].currentSrc);
            }
            $scope.showImgsList = angular.element(event.target).parent().parent().find('img');

            // $scope.showMoCrenImges= $scope.showImgsList[curIndex].currentSrc
        };

        // 直播详情图片预览
        $scope.showliveModelImg = function (currIndex, $event) {
            $scope.imgScalImg = [];
            $('#myModal').modal('show');
            $scope.showCurImg = angular.element($event.target);
            var phtos = $scope.showCurImg.parent().parent().parent().find("img");
            for (var i = 0; i < phtos.length; i++) {
                $scope.imgScalImg.push(phtos[i].currentSrc);
            }

        };
        // 视频列表图片预览
        $scope.showVedioListModelImg = function ($event) {
            $scope.imgScalImg = [];
            $('#myModal').modal('show');
            $scope.showCurImg = angular.element($event.target);
            var phtos = $scope.showCurImg.parent().find("img");
            $scope.imgScalImg.push(phtos[0].currentSrc);


        };
        // 活动图片预览
        $scope.showModelActImg = function ($event) {
            $scope.imgScalImg = [];
            $('#myModal').modal('show');
            $scope.showCurImg = angular.element($event.target);
            $scope.actImgUrl = angular.element($event.target).context.currentSrc;
            $scope.imgScalImg.push($scope.actImgUrl);
        };


        //跳转回主页
        $scope.home = function (currentPageId) {

            if(currentPageId == firstPageColumns){

                return
            }
            $scope.chanNav(firstPageColumns);
            $location.path('/home', {cache: true}, {reload: true});
        }

        //频道回退按钮
        $scope.goBack = function () {
            $window.history.back();
        }

    ////全局详情展开功能
    //window.detailLaunch=function () {
    //    $(".detailConStyle").removeClass('detailsHidde');
    //    $('.DetailConMor').css("display","none");
    //};

    // 点赞收藏初始图标
    $rootScope.detailAddPraseImag="static/13.png";
    $rootScope.detailAddStorImag="static/15.png";


    //全局样式，没有评论的情况下需要添加的颜色
    $rootScope.changeComStyle=function(){
        if(commentStyle=='blue'){
            $('.detailActComm span').css({borderLeft:"2px solid #2E97E9",color:'#2E97E9'});
            $('.commt_con a').each(function () {
                $(this).css({color:'#2E97E9'})
            })
            $('.commt_com_repla a').each(function () {
                $(this).css({color:'#2E97E9'})
            })
            $('.com-childen-more').each(function () {
                $(this).css({color:'#2E97E9'})
            })
            $('.liveFooRigPos').css({background:'#2E97E9'})
            $('.comBtnTwo').css({border: '1px solid #2E97E9',color:'#2E97E9'})
            $('#comInput').css({border: '1px solid #2E97E9'})
        }else if(commentStyle=='red'){

            $('.detailActComm span').css({borderLeft:"2px solid #f24548",color:'#f24548'});
            $('.commt_con a').each(function () {
                $(this).css({color:'#f24548'})
            })
            $('.commt_com_repla a').each(function () {
                $(this).css({color:'#f24548'})
            })
            $('.com-childen-more').each(function () {
                $(this).css({color:'#f24548'})
            })
            $('.liveFooRigPos').css({background:'#f24548'})
            $('.comBtnTwo').css({border: '1px solid #f24548',color:'#f24548'})
            $('#comInput').css({border: '1px solid #f24548'})
        }else if(commentStyle=='orange'){
            $('.detailActComm span').css({borderLeft:"2px solid #fdb92c",color:'#fdb92c'});
            $('.commt_con a').each(function () {
                $(this).css({color:'#fdb92c'})
            })
            $('.commt_com_repla a').each(function () {
                $(this).css({color:'#fdb92c'})
            })
            $('.com-childen-more').each(function () {
                $(this).css({color:'#fdb92c'})
            })
            $('.liveFooRigPos').css({background:'#fdb92c'})
            $('.comBtnTwo').css({border: '1px solid #fdb92c',color:'#fdb92c'})
            $('#comInput').css({border: '1px solid #fdb92c'})
        }else if(commentStyle=='black'){
            $('.detailActComm span').css({borderLeft:"2px solid black",color:'black'});
            $('.commt_con a').each(function () {
                $(this).css({color:'black'})
            })
            $('.commt_com_repla a').each(function () {
                $(this).css({color:'black'})
            })
            $('.com-childen-more').each(function () {
                $(this).css({color:'black'})
            })
            $('.liveFooRigPos').css({background:'black'})
            $('.comBtnTwo').css({border: '1px solid black',color:'black'})
            $('#comInput').css({border: '1px solid black'})
        }else if(commentStyle=='green'){
            $('.detailActComm span').css({borderLeft:"2px solid #5ECE5E",color:'#5ECE5E'});
            $('.commt_con a').each(function () {
                $(this).css({color:'#5ECE5E'})
            })
            $('.commt_com_repla a').each(function () {
                $(this).css({color:'#5ECE5E'})
            })
            $('.com-childen-more').each(function () {
                $(this).css({color:'#5ECE5E'})
            })
            $('.liveFooRigPos').css({background:'#5ECE5E'})
            $('.comBtnTwo').css({border: '1px solid #5ECE5E',color:'#5ECE5E'})
            $('#comInput').css({border: '1px solid #5ECE5E'})
        }else if(commentStyle=='gray'){
            $('.detailActComm span').css({borderLeft:"2px solid #999",color:'#999'});
            $('.commt_con a').each(function () {
                $(this).css({color:'#999'})
            })
            $('.commt_com_repla a').each(function () {
                $(this).css({color:'#999'})
            })
            $('.com-childen-more').each(function () {
                $(this).css({color:'#999'})
            })
            $('.liveFooRigPos').css({background:'#999'})
            $('.comBtnTwo').css({border: '1px solid #999',color:'#999'})
            $('#comInput').css({border: '1px solid #999'})
        }

    }

}]);

//时间显示样式
app.filter('fomatTime', function () {
    return function (valueTime) {

        var oldData = new Date(valueTime.slice(0,-2).replace(/-/g, "/"));
        var newData=new Date();
        var diffTime=Math.abs(oldData - new Date());
        if(diffTime>7*24*3600*1000){
            console.log("一周之外");
            var dayNum=valueTime.slice(5,16);
            return dayNum;

        }else if(diffTime<7*24*3600*1000&&diffTime>24*3600*1000){
            // console.log("一周之内");
            var time =newData.getTime()-oldData.getTime();
            var dayNum=Math.floor(time/(24*60*60*1000));
            return dayNum+"天前";

        }else if(diffTime<24*3600*1000&&diffTime>3600*1000){
            // console.log("一天之内");
            var time =newData.getTime()-oldData.getTime();
            var dayNum=Math.floor(time/(60*60*1000));
            return dayNum+"小时前";

        }else if(diffTime<3600*1000&&diffTime>0){
            // console.log("一小时之内");
            var time =newData.getTime()-oldData.getTime();
            var dayNum=Math.floor(time/(60*1000));
            return dayNum+"分钟前";

        }
       /* else if(diffTime<60*1000&&diffTime>0){
            // console.log("几分钟之内");
            var time =newData.getTime()-oldData.getTime();
            var dayNum=Math.floor(time/(60*1000));
            return dayNum+"分钟前";

        }*/
    };
});
//活动详情，年月时分
app.filter('actHour', function () {
    return function (value) {
       if(value){
           var dayNum=value.slice(5,16);
           return dayNum;
       }
    };
});
//保留时分秒
app.filter('cutHour', function () {
    return function (value) {
        var indexSpac=value.indexOf(" ");
        var lastHourString=value.substring(indexSpac);
        return lastHourString;
    };
});
//保留年月日
app.filter('cutDay', function () {
    return function (value) {
        if(value){
            var indexSpac=value.indexOf(" ");
            var lastHourString=value.substring(0,indexSpac);
            return lastHourString;
        }
    };
});
//详情时间，到秒
app.filter('cutSecond', function () {
    return function (value) {
        if(value){
            var indexSpac=value.indexOf(":");
            var lastHourString=value.substring(0,indexSpac+3);
            return lastHourString;
        }
    };
});
//主播视频时长转换
app.filter('durationTime', function () {
    return function (value) {
        if(value){
                var theTime = parseInt(value);// 秒
                var theTime1 = 0;// 分
                var theTime2 = 0;// 小时
                if(theTime > 60) {
                    theTime1 = parseInt(theTime/60);
                    theTime = parseInt(theTime%60);
                    if(theTime1 > 60) {
                        theTime2 = parseInt(theTime1/60);
                        theTime1 = parseInt(theTime1%60);
                    }
                }

                var result = ""+parseInt(theTime)+"";

                if(result >= 0 && result <= 9){
                    result = "0"+ result;
                }else{
                    result = ""+ result;
                }

                if(theTime1 > 0) {

                    if(parseInt(theTime1)>= 1 && parseInt(theTime1)<=9){
                        result = "0"+parseInt(theTime1)+":"+result;
                    }else{
                        result = ""+parseInt(theTime1)+":"+result;
                    }

                }else{
                    result = "00" + ":" + result;
                }
                if(theTime2 > 0) {
                    if(parseInt(theTime2) > 0){
                        if(parseInt(theTime2)>= 1 && parseInt(theTime2)<=9){
                            result = "0"+parseInt(theTime2)+":"+result;
                        }else{
                            result = ""+parseInt(theTime2)+":"+result;
                        }

                    }

                }
            return result;
         }else{
           var result = "00"+ ":" + "00";
           return result;
        }

     }
});
//直播详情判断mp3.mp4类型
app.filter('urlType', function () {
    return function (value) {
        var urlTypes=value.slice(-3)
        return urlTypes;
    };
});
app.directive('repeatFinish',function(){
    return {
        link: function(scope,element,attr){
            if(scope.$last == true){
                console.log('ng-repeat执行完毕')
                $(".gation .nav ul li").eq(lightIndex).find("a").css("color","#fc9105");

                $(".channelLists li").eq(lightIndex).siblings().find("a").css("color","#4B4B4B");
                $(".channelLists li").eq(lightIndex).siblings().css("border","1px solid #E3E3E3");
                $(".channelLists li").eq(lightIndex).find("a").css("color","#fc9105");
                $(".channelLists li").eq(lightIndex).css("border","1px solid #fc9105");
                $(".gation li .navBotLine").eq(lightIndex).css("display","block");
               // transLf=lightIndex*60;
               // $(".scroller").css("transform","translate(-"+transLf+"px, 0px) translateZ(0px)");
            }
        }
    }
});

//app下载指令
app.directive("appDownLoad", function() {
    return {
        template : '<div class="xyapp" style="text-align: center">'+
        '<div><img src="static/18.png">'+
        '<span>更多精彩下载app客户端</span></div>'+
        '</div>'
    };
});
//无最新评论显示指令
app.directive("noLatestComments", function() {
    return {
        template : '<div style="text-align: center;color: #999999;font-size:1.066rem">' +
        '目前没有评论，欢迎你发表评论</div>'
    };
});

//评论换肤
app.directive('commRepeatFinish',function(){
    return {
        link: function(scope,element,attr){
            if(scope.$last == true){
                console.log('commt ng-repeat执行完毕')
                   setTimeout(function(){
                      if(commentStyle=='blue'){
                          $('.detailActComm span').css({borderLeft:"2px solid #2E97E9",color:'#2E97E9'});
                          $('.commt_con a').each(function () {
                              $(this).css({color:'#2E97E9'})
                          })
                          $('.commt_com_repla a').each(function () {
                              $(this).css({color:'#2E97E9'})
                          })
                          $('.com-childen-more').each(function () {
                              $(this).css({color:'#2E97E9'})
                          })
                          $('.liveFooRigPos').css({background:'#2E97E9'})
                          $('.comBtnTwo').css({border: '1px solid #2E97E9',color:'#2E97E9'})
                          $('#comInput').css({border: '1px solid #2E97E9'})
                      }else if(commentStyle=='red'){

                          $('.detailActComm span').css({borderLeft:"2px solid #f24548",color:'#f24548'});
                          $('.commt_con a').each(function () {
                              $(this).css({color:'#f24548'})
                          })
                          $('.commt_com_repla a').each(function () {
                              $(this).css({color:'#f24548'})
                          })
                          $('.com-childen-more').each(function () {
                              $(this).css({color:'#f24548'})
                          })
                          $('.liveFooRigPos').css({background:'#f24548'})
                          $('.comBtnTwo').css({border: '1px solid #f24548',color:'#f24548'})
                          $('#comInput').css({border: '1px solid #f24548'})
                      }else if(commentStyle=='orange'){
                          $('.detailActComm span').css({borderLeft:"2px solid #fdb92c",color:'#fdb92c'});
                          $('.commt_con a').each(function () {
                              $(this).css({color:'#fdb92c'})
                          })
                          $('.commt_com_repla a').each(function () {
                              $(this).css({color:'#fdb92c'})
                          })
                          $('.com-childen-more').each(function () {
                              $(this).css({color:'#fdb92c'})
                          })
                          $('.liveFooRigPos').css({background:'#fdb92c'})
                          $('.comBtnTwo').css({border: '1px solid #fdb92c',color:'#fdb92c'})
                          $('#comInput').css({border: '1px solid #fdb92c'})
                      }else if(commentStyle=='black'){
                          $('.detailActComm span').css({borderLeft:"2px solid black",color:'black'});
                          $('.commt_con a').each(function () {
                              $(this).css({color:'black'})
                          })
                          $('.commt_com_repla a').each(function () {
                              $(this).css({color:'black'})
                          })
                          $('.com-childen-more').each(function () {
                              $(this).css({color:'black'})
                          })
                          $('.liveFooRigPos').css({background:'black'})
                          $('.comBtnTwo').css({border: '1px solid black',color:'black'})
                          $('#comInput').css({border: '1px solid black'})
                      }else if(commentStyle=='green'){
                          $('.detailActComm span').css({borderLeft:"2px solid #5ECE5E",color:'#5ECE5E'});
                          $('.commt_con a').each(function () {
                              $(this).css({color:'#5ECE5E'})
                          })
                          $('.commt_com_repla a').each(function () {
                              $(this).css({color:'#5ECE5E'})
                          })
                          $('.com-childen-more').each(function () {
                              $(this).css({color:'#5ECE5E'})
                          })
                          $('.liveFooRigPos').css({background:'#5ECE5E'})
                          $('.comBtnTwo').css({border: '1px solid #5ECE5E',color:'#5ECE5E'})
                          $('#comInput').css({border: '1px solid #5ECE5E'})
                      }else if(commentStyle=='gray'){
                          $('.detailActComm span').css({borderLeft:"2px solid #999",color:'#999'});
                          $('.commt_con a').each(function () {
                              $(this).css({color:'#999'})
                          })
                          $('.commt_com_repla a').each(function () {
                              $(this).css({color:'#999'})
                          })
                          $('.com-childen-more').each(function () {
                              $(this).css({color:'#999'})
                          })
                          $('.liveFooRigPos').css({background:'#999'})
                          $('.comBtnTwo').css({border: '1px solid #999',color:'#999'})
                          $('#comInput').css({border: '1px solid #999'})
                      }
                   },500)
                }
            }
        }

});
//占位图
function globalBitmap(item){
    item.src='static/45.png'
}
//普通用户评论使用头像
function changeUserIcon(item){
    item.src='static/21.png'
}
//官网用户评论使用头像
function changeOffialUserIcon(item){
    item.src='static/58.png'
}


